<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>go命令操作工具 | haijd</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="Golang入门" />
  
  
  
  
  <meta name="description" content="查看Go命令可以在命令行中执行go命令来查看所有的go命令：">
<meta name="keywords" content="Golang入门">
<meta property="og:type" content="article">
<meta property="og:title" content="Go命令操作工具">
<meta property="og:url" content="http://www.hais2.com/2017/08/09/Go命令操作工具/index.html">
<meta property="og:site_name" content="haijd">
<meta property="og:description" content="查看Go命令可以在命令行中执行go命令来查看所有的go命令：">
<meta property="og:locale" content="default">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/c55a7aeely1ficnszlhh9j20go098jrl.jpg">
<meta property="og:updated_time" content="2017-09-05T14:47:27.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Go命令操作工具">
<meta name="twitter:description" content="查看Go命令可以在命令行中执行go命令来查看所有的go命令：">
<meta name="twitter:image" content="http://ww1.sinaimg.cn/large/c55a7aeely1ficnszlhh9j20go098jrl.jpg">
  
    <link rel="alternate" href="/atom.xml" title="haijd" type="application/atom+xml">
  
  <link rel="icon" href="/css/images/favicon.ico">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/9749f0/00000000000000000001008f/27/l?subset_id=2&fvd=n5) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/90cf9f/000000000000000000010091/27/l?subset_id=2&fvd=n7) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/8a5494/000000000000000000013365/27/l?subset_id=2&fvd=n4) format("woff2");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/d337d8/000000000000000000010095/27/l?subset_id=2&fvd=i4) format("woff2");font-weight:400;font-style:italic;}</style>
    
  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Yanone+Kaffeesatz%3A200%2C300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">
  <link rel="stylesheet" href="/css/style.css">

  <script src="/js/jquery-3.1.1.min.js"></script>

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css" >
  <link rel="stylesheet" href="/css/hiero.css" >
  <link rel="stylesheet" href="/css/glyphs.css" >
  
    <link rel="stylesheet" href="/css/vdonate.css" >
  

</head>

<script>
var themeMenus = {};

  themeMenus["/"] = "Home"; 

  themeMenus["/archives"] = "Archives"; 

  themeMenus["/categories"] = "Categories"; 

  themeMenus["/tags"] = "Tags"; 

  themeMenus["/about"] = "About"; 

</script>


  <body data-spy="scroll" data-target="#toc" data-offset="50">


  <header id="allheader" class="site-header" role="banner">
  <div class="clearfix container">
      <div class="site-branding">

          <h1 class="site-title">
            
              <a href="/" title="haijd" rel="home"> haijd </a>
            
          </h1>

          
            <div class="site-description">Stay Hungry,Stay Foolish</div>
          
            
          <nav id="main-navigation" class="main-navigation" role="navigation">
            <a class="nav-open">Menu</a>
            <a class="nav-close">Close</a>
            <div class="clearfix sf-menu">

              <ul id="main-nav" class="nmenu sf-js-enabled">
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/">Home</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/archives">Archives</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/categories">Categories</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/tags">Tags</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/about">About</a> </li>
                    
              </ul>
            </div>
          </nav>


      </div>
  </div>
</header>




  <div id="container">
    <div id="wrap">
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-Go命令操作工具" style="width: 66%; float:left;" class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
<div class="article-gallery">
  <div class="article-gallery-photos">
    
      <a class="article-gallery-img fancybox" href="http://ww1.sinaimg.cn/large/c55a7aeely1ficnszlhh9j20go098jrl.jpg" rel="gallery_cjie4nafp003g3swakxv7ibzn">
        <img src="http://ww1.sinaimg.cn/large/c55a7aeely1ficnszlhh9j20go098jrl.jpg" itemprop="image">
      </a>
    
  </div>
</div>

    
      <header class="article-header">
        
  
    <h1 class="thumb" class="article-title" itemprop="name">
      Go命令操作工具
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	Posted on <a href="/2017/08/09/Go命令操作工具/" class="article-date">
	  <time datetime="2017-08-09T13:09:03.000Z" itemprop="datePublished">August 9, 2017</time>
	</a>

      
	<span id="busuanzi_container_page_pv">
	  本文总阅读量<span id="busuanzi_value_page_pv"></span>次
	</span>

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="查看Go命令"><a href="#查看Go命令" class="headerlink" title="查看Go命令"></a>查看Go命令</h2><p>可以在命令行中执行<code>go</code>命令来查看所有的go命令：<br><img src="http://ww1.sinaimg.cn/large/c55a7aeely1fids4wnmohj20gj0i5t9i.jpg" alt=""><br><a id="more"></a></p>
<h2 id="Go命令"><a href="#Go命令" class="headerlink" title="Go命令"></a>Go命令</h2><h3 id="go-build"><a href="#go-build" class="headerlink" title="go build"></a>go build</h3><p>主要用来编译代码，在编译的过程中，可以同时编译代码中引用的其他包。       </p>
<ul>
<li>对于普通包，执行<code>go build</code>后不会生成任何文件。(执行<code>gi install</code>可以在<code>$GOPATH/pkg</code>目录下生成对应的文件)</li>
<li>如果是main包，执行<code>go build</code>后，会在当前的目录下生成一个可执行文件。(使用<code>go install</code>或<code>go build -o [path]/a.exe</code>可以在<code>$GOPATH/bin</code>目录下生成相应的文件)</li>
<li><code>go build</code>默认会编译当前目录下的所有go文件；如果只想编译某一个文件，可以在<code>go build</code>之后加上文件名，例如：<code>go build name.go</code>。</li>
<li>使用<code>go build -o namexx.exe</code>可以指定编译输出的文件名；默认的名称有两种情况：如果当前不是main包，那么就是package名；如果是main包那么就是第一个源文件的文件名。</li>
<li><code>go build</code>会忽略目录下以“<code>_</code>”或者“<code>.</code>”开头的文件。</li>
<li>如果需要针对不同的操作系统进行不同的处理，可以根据不同系统名称后缀来命名文件，例如有一个读取数组的程序，针对不同的操作系统的执行代码有差异的，那么就有这么几个源文件：<code>array_linux.go</code>、<code>array_darwin.go</code>、<code>array_windows.go</code>、<code>array_freebsd.go</code>，在不同的操作系统下编译会选择相应系统名结尾的文件，忽略其他文件。</li>
</ul>
<h4 id="参数介绍"><a href="#参数介绍" class="headerlink" title="参数介绍"></a>参数介绍</h4><ul>
<li><code>-o</code> 指定输出的文件名，可以带路径输出：<code>go build a/b/c/name.exe</code></li>
<li><code>-n</code> 把需要执行的编译命令打印出来，但是不执行，只输出。</li>
<li><code>-v</code> 打印出正在编译的包名</li>
<li><code>-x</code> 和<code>-n</code>相同，只是<code>-x</code>在打印的同时会执行编译</li>
</ul>
<h3 id="go-clean"><a href="#go-clean" class="headerlink" title="go clean"></a>go clean</h3><p>这个命令是用来删除掉当前包中编译生成的文件，只剩下源文件。</p>
<h4 id="参数介绍-1"><a href="#参数介绍-1" class="headerlink" title="参数介绍"></a>参数介绍</h4><ul>
<li><code>-i</code> 清除使用<code>go install</code>安装的文件(关联的安装包和可运行文件)。</li>
<li><code>-n</code> 把需要执行清除命令打印出来，但是不执行。</li>
<li><code>-r</code> 循环清除在import中引入的包。</li>
<li><code>-x</code> 和<code>-n</code>一样，只不过在打印的同时会执行清除命令。</li>
</ul>
<h3 id="go-fmt"><a href="#go-fmt" class="headerlink" title="go fmt"></a>go fmt</h3><p>这个命令可以格式化你源文件中的代码，消除源文件中的编码不规范。</p>
<h4 id="参数介绍-2"><a href="#参数介绍-2" class="headerlink" title="参数介绍"></a>参数介绍</h4><ul>
<li><code>-l</code> 列出需要格式化的文件。</li>
<li><code>-w</code> 把格式化后的内容直接写入对应的源文件中。</li>
<li><code>-s</code> 简化文件中的代码。</li>
<li><code>-d</code> 打印格式化前后的内容对比，不写入文件，默认是false。</li>
<li><code>-e</code> 打印所有的语法错误。如果没有这个参数，默认只会打印前10个错误。</li>
</ul>
<h3 id="go-get"><a href="#go-get" class="headerlink" title="go get"></a>go get</h3><p>这个命令用来拉取远程包，并执行<code>go install</code>命令安装。<br>支持从BitBucket、GitHub、Google Code和Launchpad获取包文件，获取是需要安装对应的源码版本管理工具：</p>
<table>
<thead>
<tr>
<th style="text-align:left">远程</th>
<th style="text-align:left">工具</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">BitBucket</td>
<td style="text-align:left">Mercurial</td>
</tr>
<tr>
<td style="text-align:left">GitHub</td>
<td style="text-align:left">Git</td>
</tr>
<tr>
<td style="text-align:left">Google Code Project Hosting</td>
<td style="text-align:left">Git, Mercurial, Subversion</td>
</tr>
<tr>
<td style="text-align:left">Launchpad</td>
<td style="text-align:left">Bazaar</td>
</tr>
</tbody>
</table>
<h4 id="参数介绍-3"><a href="#参数介绍-3" class="headerlink" title="参数介绍"></a>参数介绍</h4><ul>
<li><code>-d</code> 只下载包，不安装(不执行<code>go install</code>)。</li>
<li><code>-u</code> 强制从网络更新包和包的依赖。</li>
<li><code>-f</code> 只在包含了<code>-u</code>参数的时候有效，不让<code>-u</code>去验证import的包是否都获取了。</li>
<li><code>-t</code> 同时获取需要为运行测试所需要的包。</li>
<li><code>-v</code> 显示执行的命令。</li>
</ul>
<h3 id="go-install"><a href="#go-install" class="headerlink" title="go install"></a>go install</h3><p>这个命令用来生成可执行文件或者<code>.a</code>包，并且会把编译好的文件移动到<code>$GOPATH/pkg</code>或者<code>$GOPATH/bin</code>目录下。</p>
<h4 id="参数介绍-4"><a href="#参数介绍-4" class="headerlink" title="参数介绍"></a>参数介绍</h4><p>支持<code>go build</code>的所有参数。</p>
<h3 id="go-test"><a href="#go-test" class="headerlink" title="go test"></a>go test</h3><p>这个命令会自动读取源文件目录下面名称为<code>*_test.go</code>的文件，生成并运行测试用的可执行文件，输出测试结果。</p>
<h3 id="go-tool"><a href="#go-tool" class="headerlink" title="go tool"></a>go tool</h3><p>这个命令下面有很多参数命令。</p>
<h4 id="参数介绍-5"><a href="#参数介绍-5" class="headerlink" title="参数介绍"></a>参数介绍</h4><ul>
<li><code>fix</code> 修改老版本的代码到新版本。</li>
<li><code>vet directory|files</code> 用来分析当前目录下的代码是否编写正确(参数、函数、无用代码之类)</li>
</ul>

      
    </div>
    <footer class="entry-meta entry-footer">
      
	<span class="ico-folder"></span>
    <a class="article-category-link" href="/categories/Golang/">Golang</a>

      
  <span class="ico-tags"></span>
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Golang入门/">Golang入门</a></li></ul>

      
        <div id="donation_div"></div>

<script src="/js/vdonate.js"></script>
<script>
var a = new Donate({
  title: '如果觉得我的文章对您有用，请随意打赏。您的支持将鼓励我继续创作!', // 可选参数，打赏标题
  btnText: 'Donate', // 可选参数，打赏按钮文字
  el: document.getElementById('donation_div'),
  wechatImage: '/css/images/wechatPay.png',
  alipayImage: '/css/images/alipay.jpg'
});
</script>
      

      
        
	<section id="comments" class="comment">
	  <div id="disqus_thread">
	  <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
	  </div>
	</section>

	<script type="text/javascript">
	var disqus_shortname = 'haijdblog';
	(function(){
	  var dsq = document.createElement('script');
	  dsq.type = 'text/javascript';
	  dsq.async = true;
	  dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
	  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	}());
	(function(){
	  var dsq = document.createElement('script');
	  dsq.type = 'text/javascript';
	  dsq.async = true;
	  dsq.src = '//' + disqus_shortname + '.disqus.com/count.js';
	  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	}());
	</script>


      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2017/08/11/Go语言基础知识/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Go语言基础知识
        
      </div>
    </a>
  
  
    <a href="/2017/08/08/GO环境安装部署/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">GO环境安装部署</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="sidebar">
    <div id="toc" class="toc-article">
    <strong class="toc-title">Contents</strong>
    
      <ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#查看Go命令"><span class="nav-number">1.</span> <span class="nav-text">查看Go命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Go命令"><span class="nav-number">2.</span> <span class="nav-text">Go命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#go-build"><span class="nav-number">2.1.</span> <span class="nav-text">go build</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#参数介绍"><span class="nav-number">2.1.1.</span> <span class="nav-text">参数介绍</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#go-clean"><span class="nav-number">2.2.</span> <span class="nav-text">go clean</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#参数介绍-1"><span class="nav-number">2.2.1.</span> <span class="nav-text">参数介绍</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#go-fmt"><span class="nav-number">2.3.</span> <span class="nav-text">go fmt</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#参数介绍-2"><span class="nav-number">2.3.1.</span> <span class="nav-text">参数介绍</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#go-get"><span class="nav-number">2.4.</span> <span class="nav-text">go get</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#参数介绍-3"><span class="nav-number">2.4.1.</span> <span class="nav-text">参数介绍</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#go-install"><span class="nav-number">2.5.</span> <span class="nav-text">go install</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#参数介绍-4"><span class="nav-number">2.5.1.</span> <span class="nav-text">参数介绍</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#go-test"><span class="nav-number">2.6.</span> <span class="nav-text">go test</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#go-tool"><span class="nav-number">2.7.</span> <span class="nav-text">go tool</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#参数介绍-5"><span class="nav-number">2.7.1.</span> <span class="nav-text">参数介绍</span></a></li></ol></li></ol></li></ol>
    
    </div>
  </aside>
</section>
        
      </div>
      <footer id="footer" class="site-footer">
  

  <div class="clearfix container">
      <div class="site-info">
	      &copy; 2018 haijd All Rights Reserved.
          
            <span id="busuanzi_container_site_uv">
              本站访客数<span id="busuanzi_value_site_uv"></span>人次  
              本站总访问量<span id="busuanzi_value_site_pv"></span>次
            </span>
          
      </div>
      <div class="site-credit">
        Theme by <a href="https://github.com/iTimeTraveler/hexo-theme-hiero" target="_blank">hiero</a>
      </div>
  </div>
</footer>


<!-- min height -->

<script>
    var contentdiv = document.getElementById("content");

    contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";
</script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/scripts.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/main.js"></script>








	<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js" async=""></script>
</body>
</html>
